package com.ruoyi.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.domain.GoodsSkuInfo;
import com.ruoyi.service.IGoodsSkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/webshop/goodsSkuInfo")
public class GoodsSkuInfoController extends BaseController {
    @Autowired
    private IGoodsSkuInfoService goodsSkuInfoService;

    // 全查
    @GetMapping("/list")
    public AjaxResult list(){
        List<GoodsSkuInfo> list = goodsSkuInfoService.list();
        return success(list);
    }


    //// 全查
    //@GetMapping("/listBySupplier/{supplierId}")
    //public AjaxResult listBySupplier(@PathVariable Integer supplierId){
    //    List<GoodsSkuInfo> list = goodsSkuInfoService.list();
    //    return success(list);
    //}
    //

    @GetMapping("/listForPage")
    public TableDataInfo listForPage(GoodsSkuInfo goodsSkuInfo) {
        System.out.println("goodsSkuInfo = " + goodsSkuInfo);
        startPage();
        List<GoodsSkuInfo> list = goodsSkuInfoService.listForPage(goodsSkuInfo);

        return getDataTable(list);
    }
    // 根据id查一条
    @GetMapping("/{id}")
    public AjaxResult getInfo(@PathVariable Long id){
        System.out.println("id = " + id);
        GoodsSkuInfo goodsSkuInfo = goodsSkuInfoService.getById(id);
        return success(goodsSkuInfo);
    }
    // 添加
    @PostMapping()
    public AjaxResult add(@RequestBody GoodsSkuInfo goodsSkuInfo){
        System.out.println("goodsSkuInfo = " + goodsSkuInfo);
        int add = goodsSkuInfoService.save(goodsSkuInfo);
        return toAjax(add);
    }
    // 修改
    @PutMapping()
    public AjaxResult edit(@RequestBody GoodsSkuInfo goodsSkuInfo){
        System.out.println("goodsSkuInfo = " + goodsSkuInfo);
        int edit = goodsSkuInfoService.updateById(goodsSkuInfo);
        return toAjax(edit);
    }
    // 根据ids删除多条
    @DeleteMapping("/{ids}")
    public AjaxResult deleteMany(@PathVariable Long[] ids){
        System.out.println("ids = " + Arrays.toString(ids));
        int delete = goodsSkuInfoService.removeByIds(ids);
        return toAjax(delete);
    }
}
